<?php
session_start();
include('productDatabase.php');

class ProductController{
	public function insert_product(){
		if (isset($_POST['Category']))
			{
				$myDatabase = new ProductDatabase();
				$myDatabase->insert($_POST["Category"],$_POST["Price"],$_POST["Description"]);
			}
		
	}
	public function search_pid(){
		if (isset($_POST['Product_ID']))
			{
				$myDatabase = new ProductDatabase();
				$myDatabase->searchByPid($_POST["Product_ID"]);
			}
		
	}
	public function search_category(){
		if (isset($_POST['Category']))
			{
				$myDatabase = new ProductDatabase();
				$myDatabase->searchByCategory($_POST["Category"]);
			}
		
	}
	public function edit_product(){
		if (isset($_GET['Product_ID']))
			{
				$myDatabase = new ProductDatabase();
				$myDatabase->editProduct($_GET['Product_ID'],$_POST["Category"],$_POST["Price"],$_POST["Description"]);
			}
	}
	
	public function delete_product(){
		if (isset($_GET['Product_ID']))
			{
				$myDatabase = new ProductDatabase();
				$myDatabase->deleteProduct($_GET['Product_ID']);
			}
	}
		
}
	if($_GET['id']==0)
	{
		$obj = new ProductController();
		$obj->insert_product();
	}
	if($_GET['id']==1)
	{
		$obj = new ProductController();
		$obj->search_pid();
	}
	if($_GET['id']==2)
	{
		$obj = new ProductController();
		$obj->search_category();
	}
	if($_GET['id']==3)
	{
		$obj = new ProductController();
		$obj->edit_product();
	}
	if($_GET['id']==4)
	{
		$obj = new ProductController();
		$obj->delete_product();
	}
?>